home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 7088 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.3 KB

  1. Path: ix.netcom.com!netnews
  2. From: regmia@ix.netcom.com
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: A simple "find the bug" (please! I need help :)
  5. Date: Wed, 21 Feb 1996 06:32:23 GMT
  6. Organization: Netcom
  7. Message-ID: <4gee6a$et3@cloner3.netcom.com>
  8. References: <4gdr6n$6p0@guava.epix.net>
  9. NNTP-Posting-Host: ix-lv3-20.ix.netcom.com
  10. X-NETCOM-Date: Tue Feb 20 10:30:34 PM PST 1996
  11. X-Newsreader: Forte Free Agent 1.0.82
  12.  
  13. If that is actually what your program looks like then the problem is
  14. simple.
  15.  
  16. result is not global, result only has scope within the function
  17. getnums().
  18.  
  19. define result along with num1 and num2 and everything should
  20. work. NOTE: I'm making an assumption about your return value for
  21. getnum() I hope you just forgot here.
  22.  
  23.  
  24. jgvd@epix.net (Jon) wrote:
  25.  
  26. >I wrote this just now and it's telling me that when i try to cout the 
  27. >result at the bottom, it is an undefined value even though I did return 
  28. >the result var...  See if you can help.
  29.  
  30. >#include <iostream.h>
  31.  
  32. >float num1;
  33. >float num2;
  34.  
  35. >getnums () {
  36.  
  37. >float result = num1 +num2;
  38.  
  39. >cout << "What number?\n";
  40. >cin >> num1;
  41. >cout << "And?\n";
  42. >cin >> num2;
  43.  
  44. >return result;
  45. >}
  46.  
  47. >main (){
  48.  
  49. >getnums ();
  50.  
  51.  
  52. >cout << result;
  53. >}
  54.  
  55. >        ^^^^^^ right there is the result i want printed but it does not 
  56. >recognize it even though I did try to return the value in the function 
  57. >getnums... am I missing something?
  58.  
  59. >Jon
  60.  
  61.  
  62.  
  63.